﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WCell.Util.Commands;
using WCell.Constants.Items;
using WCell.RealmServer.Database;
using WCell.RealmServer.Mail;

namespace WCell.RealmServer.Commands
{
	public class MailCommand : RealmServerCommand
	{
		protected override void Initialize()
		{
			Init("Mail");
		}

		public class SendMailCommand : SubCommand
		{
			protected override void Initialize()
			{
				Init("Send", "S");
				//ParamInfo = "[-i <ItemId>] <subject>, <text>";
				ParamInfo = "<recipient> <subject>, <text>";
			}

			public override void Process(CmdTrigger<RealmServerCmdArgs> trigger)
			{
				var mod = trigger.Text.NextModifiers();

				//if (mod.Contains("i"))
				//{
				//    var itemId = trigger.Text.NextEnum(ItemId.None):
				//    if (itemId == ItemId.None)
				//    {
				//        trigger.Reply("Invalid ItemId.");
				//        return;
				//    }
				//}
				var recipientName = trigger.Text.NextWord();
				var subject = trigger.Text.NextWord(",");
				var text = trigger.Text.Remainder;

				if (recipientName.Length == 0 || !MailMgr.SendMail(recipientName, subject, text))
				{
					trigger.Reply("Could not send mail - Unknown Recipient: " + recipientName);
				}
				else
				{
					trigger.Reply("Done.");
				}
			}
		}
	}
}
